package com.mentalhealthplatform.studentV3.ai.message;



import com.mentalhealthplatform.studentV3.ai.session.AiSession;
import org.springframework.ai.chat.messages.MessageType;

import java.util.Objects;

public class AiMessageInput {

    private MessageType type;
    private String textContent;
    private String sessionId;

    public AiMessageInput() {
    }

    public AiMessageInput(AiMessage base) {
        this.type = MessageType.valueOf(base.getType());
        this.textContent = base.getTextContent();
        this.sessionId = base.getSession().getId();
    }

    public MessageType getType() {
        return type;
    }

    public void setType(MessageType type) {
        this.type = type;
    }

    public String getTextContent() {
        return textContent;
    }

    public void setTextContent(String textContent) {
        this.textContent = textContent;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public AiMessageImpl toEntity() {
        AiMessageImpl aiMessage = new AiMessageImpl();
        aiMessage.setType(type.name());
        aiMessage.setTextContent(textContent);

        AiSession session = new AiSession();
        session.setId(sessionId);
        aiMessage.setSession(session);

        return aiMessage;
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, textContent, sessionId);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AiMessageInput that = (AiMessageInput) o;
        return type == that.type &&
                Objects.equals(textContent, that.textContent) &&
                Objects.equals(sessionId, that.sessionId);
    }

    @Override
    public String toString() {
        return "AiMessageInput{" +
                "type=" + type +
                ", textContent='" + textContent + '\'' +
                ", sessionId='" + sessionId + '\'' +
                '}';
    }
}